<meta charset="utf-8">

<?php

	ob_clean();
		
	
		$per_page=3;

		$pagenum=5;
		/*判断传参是否有值然后给于一个变量*/
		$cur_page=!empty($_GET['p'])?$_GET['p']:1;






		/*当前页码减一，乘以固定页数据，然后给于一个变量*/
		$off=($cur_page-1)*$per_page;


	/*die;*/
		$pages=getpages($link,'news',1,$cur_page);

		/*数据库查询语句；查找从那天数据开始；到那条数据结束*/
		// $sql="select `news`.*,`cate`.news from `news`,`cate` where `news`.cate_id= `cate`.id order by `news`.`id` desc limit $off,$per_page";

												
		
		 // $row = mysqli_query($link,$sql);
		 // print_r($row );die;
		// $a=array();
		 /*循环受影响的行数*/
        // while ($arr=mysqli_fetch_assoc($row)) {
        	// $a[]=$arr;

        	
        // };
      /*  print_r($a)
        	;die;*/
        $a=array();
     	$a=gatselect('`news`,`cate`','`news`.cate_id=`cate`.id',"$off,$per_page",'`news`.`id` desc','`news`.*,`cate`.news');
     	/*print_r($a);die;*/

        if (!empty($_SERVER['HTTP_X_REQUESTED_WITH'])) {

			if(empty($_POST['title'])){
        	$json['a']=$a;
        	
        	$json['pages']=$pages;
        	

        	echo json_encode($json);die;

	        }else{
	        $where['title']=$_POST['title'];
	        $where['cate_id']=$_POST['cate_id'];
	        $where['content']=$_POST['content'];
			$where['status']=$_POST['status'];
			
		

			$json=add('news',$where);

			echo $json;die;
        }
        }

     



   
  		include( VIEW_PATH.$admin.'layst.html');


?>
